package day09;

import java.util.HashMap;
import java.util.Map;

public class 两数之和610 {
    public int[] twoSum(int[] nums, int target) {
        int n = nums.length;
        // 创建一个map
        Map<Integer, Integer> hashMap = new HashMap<>();
        for (int i = 0; i < n; i++) {
            if (hashMap.containsKey(target - nums[i])) {
                return new int[] { i, hashMap.get(target - nums[i]) };
            } else {
                hashMap.put(nums[i], i);
            }
        }
        return new int[0];
    }
}
